<template>
	<view>
		<!-- <topbar title="" background="background:#FFDE21"></topbar> -->
		<view>
			<view class="dhl" style="background-color: #FFDE21;"></view>
			<view class="topbar box dis_f_c_c" style="background-color: #FFDE21;color: #000;">
					广告管理
			<image  class="top_jt" src="../../static/icon/back.png" mode="aspectFit" @click="go_back"></image>
			</view>
		</view>
		<view class="r_btn dis_f_l_c" @click="go_fb">
			<image src="../../static/icon/xfj.png" mode=""></image>
			<view>发布广告</view>
		</view>
		<view class="tab">
			<u-tabs :list="list" bg-color="none" active-color="#222222" bar-width="196" bar-height="4" inactive-color="#BBBBBB" :is-scroll="false" :current="current" @change="change"></u-tabs>
		</view>
		<view class="content">
			<view class="gg_part"  v-for="(item,index) in lists" @click="go_xq(item.id)">
				<view class="dis_f_sb_t" style="width: 100%;margin-bottom: 48rpx;">
					<view class="hh" style="width: 482rpx;">{{item.content}}</view>
					<view class="size_22 c_b">{{item.create_time}}</view>
				</view>
				<view class="dis_f_l_c" style="margin-bottom: 12rpx;">
					<view class="size_22 c_b">置顶剩余{{item.istop_num - item.istop_endnum}},刷新剩余{{item.refresh_num - item.refresh_endnum}}</view>
					
				</view>
				<view class="dis_f_l_c an_niu" v-if="status_true">
					<view class="btn" style="color: #5EBCA3;border: 2rpx solid #5EBCA3;" @click.stop="go_top(item.id)">置顶</view>
					<view class="btn" style="color: #6DADBE;border: 2rpx solid #6DADBE;"@click.stop="go_refresh(item.id)">自动刷新</view>
					<view class="btn" style="color: #E23C63;border: 2rpx solid #E23C63;" @click.stop="shelf(item.id)">下架</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				list: [{
					name: '待审核'
				},{
					name: '显示中'
				}, {
					name: '已下架'
				}, ],
				current:1,
				lists:[],
				status_true:true
			};
		},
		onLoad() {
			this.$.ajax(1, 'post', 'index/checktokens', {
				uid:uni.getStorageSync('uid'),
				token:uni.getStorageSync('token')
			}, (res) => {
				console.log(res)
				if(res.code == 9){
					this.$.ti_shi('token已过期，请重新登陆')
				uni.clearStorageSync()
					setTimeout( () => {
						uni.navigateTo({
							url:'/pages/login/login'
						})
					}, 1000)
				return;
				}
				else{
						this.getguang()
				}
			})
			
		},
		onBackPress(e) {
		    console.log(e);
			// return;
		    if(e.from == 'backbutton'){
				uni.switchTab({
					url:'/pages/mine/mine'
				})
		    return true;//阻止默认返回行为
		    }
			 return true;//阻止默认返回行为
		},
		onShow() {
			this.$.ajax(1, 'post', 'index/checktokens', {
				uid:uni.getStorageSync('uid'),
				token:uni.getStorageSync('token')
			}, (res) => {
				console.log(res)
				if(res.code == 9){
					this.$.ti_shi('token已过期，请重新登陆')
				uni.clearStorageSync()
					setTimeout( () => {
						uni.navigateTo({
							url:'/pages/login/login'
						})
					}, 1000)
				return;
				}
				else{
						this.getguang()
				}
			})
			
		},
		methods:{
			go_back(){
				this.$.open_tab('/pages/mine/mine')
			},
			shelf(id){
							this.$.ajax(1, 'post', 'index/shelf_guang', {
								uid:uni.getStorageSync('uid'),
								token:uni.getStorageSync('token'),
								id:id,
							}, (res) => {
								if(res.code == 1){
									this.$.ti_shi(res.msg)
									this.$.open('/pages/guang_gao/gg_gl');
								}else if(res.code == 9){
									this.$.ti_shi('token已过期，请重新登陆')
									uni.clearStorageSync()
										setTimeout( () => {
											uni.navigateTo({
												url:'/pages/login/login'
											})
										}, 1000)
									return;
								}
								
							})
						},
			go_xq(e) {
				this.$.ajax(1, 'post', 'index/checktokens', {
					uid:uni.getStorageSync('uid'),
					token:uni.getStorageSync('token')
				}, (res) => {
					console.log(res)
					if(res.code == 9){
						this.$.ti_shi('token已过期，请重新登陆')
					uni.clearStorageSync()
						setTimeout( () => {
							uni.navigateTo({
								url:'/pages/login/login'
							})
						}, 1000)
					return;
					}
					else{
							this.$.open('/pages/guang_gao/part1?id='+e)
					}
				})
				
			},
			go_top(e){
				this.$.open('/pages/xuan_shang/zhi_ding?id='+ e + '&type=' + 0)
			},
			go_refresh(e){
				this.$.open('/pages/xuan_shang/shua_xin?id='+ e + '&type=' + 0)
			},
			getguang(){
				this.$.ajax(1, 'post', 'index/getguang', {
				uid:uni.getStorageSync('uid'),
				token:uni.getStorageSync('token'),
				statuses:1,
				status:1
			}, (res) => {
				// console.log(res.list[0].user)
				if(res.code == 1){
					this.lists = res.list
				}else if(res.code == 9){
					this.$.ti_shi('token已过期，请重新登陆')
					uni.clearStorageSync()
						setTimeout( () => {
							uni.navigateTo({
								url:'/pages/login/login'
							})
						}, 1000)
					return;
				}
				
			})
			},
			del(e){
				this.$.ajax(1, 'post', 'index/delguang', {
					uid:uni.getStorageSync('uid'),
					token:uni.getStorageSync('token'),
					id:e,
				}, (res) => {
					// console.log(res.list[0].user)
					if(res.code == 1){
						this.$.ti_shi(res.msg)
						this.getguang()
					}else if(res.code == 9){
						this.$.ti_shi('token已过期，请重新登陆')
					uni.clearStorageSync()
						setTimeout( () => {
							uni.navigateTo({
								url:'/pages/login/login'
							})
						}, 1000)
					return;
					}else{
						this.$.ti_shi(res.msg)
					}
					
				})
			},
			go_fb() {
				this.$.ajax(1, 'post', 'index/checktokens', {
					uid:uni.getStorageSync('uid'),
					token:uni.getStorageSync('token')
				}, (res) => {
					console.log(res)
					if(res.code == 9){
						this.$.ti_shi('token已过期，请重新登陆')
					uni.clearStorageSync()
						setTimeout( () => {
							uni.navigateTo({
								url:'/pages/login/login'
							})
						}, 1000)
					return;
					}
					else{
						this.$.open('/pages/guang_gao/fb')
						// this.$.open('/pages/guang_gao/gg_list?cate='+e)
					}
				})
				
			},
			change(index) {
				console.log(index)
				this.current = index;
				if(index == 0){
					this.status_true = false;
					this.lists = []
					this.$.ajax(1, 'post', 'index/getguang', {
						uid:uni.getStorageSync('uid'),
						token:uni.getStorageSync('token'),
						statuses:1,
						status:0
					}, (res) => {
						// console.log(res.list[0].user)
						if(res.code == 1){
							this.lists = res.list
						}else{
							this.lists = []
						}
					})
				}else if(index == 1){
					this.status_true = true;
					this.lists = []
					this.getguang()
				}
				else{
					this.status_true = false;
					this.lists = []
					this.$.ajax(1, 'post', 'index/getguang', {
						uid:uni.getStorageSync('uid'),
						token:uni.getStorageSync('token'),
						statuses:1,
						status:2
					}, (res) => {
						// console.log(res.list[0].user)
						if(res.code == 1){
							this.lists = res.list
						}else{
							this.lists = []
						}
					})
					
				}
			}
		}
	}
</script>

<style lang="scss">
	.dhl {
		// position: absolute;
		width: 100%;
		height: var(--status-bar-height);
		position: fixed;
		top: 0;
		z-index: 999;
	}
	.topbar {
		width: 100%;
		z-index: 999;
		height: 88rpx;
		position: fixed;
		top: var(--status-bar-height);
		font-size: 34rpx;
		color: #212730;
		font-weight: bold;
		// background-image: url(../../static/index/bg.png);
		// padding: 0 0 26rpx 0rpx;
		
		.top_jt {
			width: 18rpx;
			height: 32rpx;
			position: absolute;
			left: 40rpx;
			top: 28rpx;
		}
	}
	.r_btn {
		position: fixed;
		z-index: 999;
		top: calc(var(--status-bar-height) + 22rpx);
		right: 48rpx;
	
		image {
			width: 32.99rpx;
			margin-right: 6rpx;
			height: 34rpx;
		}
	}
	.tab{
		position: fixed;
		top: calc(var(--status-bar-height) + 88rpx);
		width: 100%;
		padding: 0 48rpx;
		height: 88rpx;
		z-index: 999;
	}
	.content{
		width: 100%;
		top: calc(var(--status-bar-height) + 176rpx);
		z-index: 998;
		position: absolute;
		padding: 36rpx 24rpx;
		.gg_part{
			width: 100%;
			margin-bottom: 12rpx;
			padding: 36rpx 24rpx;
			background-color: #fff;
			border-radius: 20rpx;
			box-shadow: 0rpx 6rpx 24rpx rgba(34, 34, 34, 0.05);
			.an_niu{
				.btn{
					padding: 8rpx 29rpx;
					border-radius: 10rpx;
					margin-right: 12rpx;
					line-height: 33rpx;
					font-size: 22rpx;
				}
				.an_niu > .btn:last-child{
					margin-right: 0;
				}
			}
		}
	}
</style>
